﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using MaxStudio.Concrete.DBUtility;
using MaxStudio.Concrete.Server.Dao;
using MaxStudio.Concrete.Server.Interface; 

namespace MaxStudio.Concrete.Server.Service
{
    public class RPTMixProportionDesignService : ServiceHandle, IRPTMixProportionDesign
    {
        #region IRPTMixProportionDesign Members

        public OperationResult<List<tb_RPT_MixProportionDesign>> GetAllMixProportionDesign()
        {
            OperationResult<List<tb_RPT_MixProportionDesign>> result = new OperationResult<List<tb_RPT_MixProportionDesign>>();
            List<tb_RPT_MixProportionDesign> list = new List<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetAllMixProportionDesign();
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_MixProportionDesign>> GetSiteMixProportionDesignBySequence(string strSequence)
        {
            OperationResult<List<tb_RPT_MixProportionDesign>> result = new OperationResult<List<tb_RPT_MixProportionDesign>>();
            List<tb_RPT_MixProportionDesign> list = new List<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetSiteMixProportionDesignBySequence(strSequence);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_MixProportionDesign>> GetMixProportionDesignByProjectName(string strProjectName)
        {
            OperationResult<List<tb_RPT_MixProportionDesign>> result = new OperationResult<List<tb_RPT_MixProportionDesign>>();
            List<tb_RPT_MixProportionDesign> list = new List<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetMixProportionDesignByProjectName(strProjectName);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<List<tb_RPT_MixProportionDesign>> GetMixProportionDesignByContition(string strProjectName, string strSequence, 
                                                                                                   string strStrengthGrade, string strTeststrength, 
                                                                                                   string strDemandSlump, string strSampleName,
                                                                                                   string strDesignDate)
        {
            OperationResult<List<tb_RPT_MixProportionDesign>> result = new OperationResult<List<tb_RPT_MixProportionDesign>>();
            List<tb_RPT_MixProportionDesign> list = new List<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                list = dataContext.GetMixProportionDesignByContition(strProjectName, strSequence, strStrengthGrade, strTeststrength, 
                                                                     strDemandSlump, strSampleName, strDesignDate);
                if (list == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = list;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MixProportionDesign> GetMixProportionDesignById(int id)
        {
            ConcreteDaoDataContext dataContext = getDateContext();
            OperationResult<tb_RPT_MixProportionDesign> result = new OperationResult<tb_RPT_MixProportionDesign>();
            tb_RPT_MixProportionDesign mixProportionDesign;
            try
            {
                mixProportionDesign = dataContext.GetMixProportionDesignById(id);
                if (mixProportionDesign == null)
                {
                    result.errorMessageKey = "Error";
                }
                else
                {
                    result.obj = mixProportionDesign;
                    result.operationSuccess = true;
                }
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);

            }
            return result;
        }

        public OperationResult<tb_RPT_MixProportionDesign> CreateMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            OperationResult<tb_RPT_MixProportionDesign> result = new OperationResult<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.CreateMixProportionDesign(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MixProportionDesign> ModifyMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            OperationResult<tb_RPT_MixProportionDesign> result = new OperationResult<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.ModifyMixProportionDesign(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        public OperationResult<tb_RPT_MixProportionDesign> DeleteMixProportionDesign(tb_RPT_MixProportionDesign entity)
        {
            OperationResult<tb_RPT_MixProportionDesign> result = new OperationResult<tb_RPT_MixProportionDesign>();
            ConcreteDaoDataContext dataContext = getDateContext();
            try
            {
                dataContext.DeleteMixProportionDesign(entity);
                dataContext.SubmitChanges();
                result.obj = entity;
                result.operationSuccess = true;
            }
            catch (Exception ex)
            {
                result.exceptionString = DlHelper.ExceptionString(ex);
            }

            return result;
        }

        #endregion
    }
}
